var express = require('express');
var router = express.Router();
var MongoClient = require('mongodb').MongoClient;
var url = 'mongodb://127.0.0.1:27017/';

router.get('/list', function (req,res) {
    var filmId = parseInt(req.query.filmId)
    var results = {}
    MongoClient.connect(url, { useNewUrlParser: true }, function(err,client) {
      if (err) {
        results.code = -1
        results.msg = '数据库连接失败'
        res.json(results)
        // 关闭数据库连接
        return
      }
  
      var db = client.db('maizuo')
      db.collection('city').find().toArray(function (err,data) {
        if (err) {
          results.code = -1
          results.msg = '查询失败'
        } else {
          results.code = 0
          results.msg = '查询成功'
          results.data = data
        }
        client.close()
        res.json(results)
      })
    })
  })
  
  module.exports = router;
